package com.ruoyi.web.controller.reserve;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.reserve.domain.Checkitem;
import com.ruoyi.reserve.domain.Order;
import com.ruoyi.reserve.service.impl.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/reserve/order")
public class OrderController extends BaseController {

    @Autowired
    private IOrderService orderService;

    /**
     * 获取预约列表
     */
    @GetMapping("/list")
    public TableDataInfo selectOrderList(Order order)
    {
        startPage();
        List<Order> list = orderService.selectOrderList(order);
        TableDataInfo tableDataInfo = getDataTable(list);
        return tableDataInfo;
    }

    /**
     * 新增时通过模糊查询获得单条数据进行文本框填充
     */
    @GetMapping("/list1")
    public List<Order> selectSerchList(Order order) {
        List<Order> list1 = orderService.selectOrderInsertList(order);
        return list1;
    }


    /**
     * 修改预约在状态为确认预约
     */
    @Log(title = "预约列表管理", businessType = BusinessType.UPDATE)
    @PostMapping("/updateComfirmOrderStatus")
    public AjaxResult updateComfirmOrderStatus(@RequestBody Order order)
    {
            return toAjax(orderService.updateConfirmOrderStatus(order));

    }

    /**
     * 修改预约在状态为取消预约
     */
    @Log(title = "预约列表管理", businessType = BusinessType.UPDATE)
    @PostMapping("/updateCancelOrderStatus")
    public AjaxResult updateCancelOrderStatus(@RequestBody Order order)
    {
        return toAjax(orderService.updateCancelOrderStatus(order));

    }



    /**
     * 新增预约
     */
    @Log(title = "预约列表管理", businessType = BusinessType.INSERT)
    @PostMapping("/addOrder")
    public AjaxResult add(@RequestBody Order order)
    {
        String orderDate = DateUtils.dateTime(order.getOrderDateForm());
        order.setOrderDate(orderDate);
        return toAjax(orderService.insertOrder(order));
    }
}
